function user_edit(){
    var password=document.getElementById("password").value;
    var password1=document.getElementById("password1").value;
    var password2=document.getElementById("password2").value;
    if( password=="" || password1=="" || password2==""){
        layer.alert("不能留空！");
        return false;
    }
    if(password1==password2){
        var index1 = layer.load(3, {
            shade: [0.5,'#000'] //0.1透明度的白色背景
        });
        $.post(
            "controler.php?handle=user_edit",
            {
                password:password,
                password1:password1,
            },
            function (msg) {
                layer.close(index1);
                result(msg);
            }
        );
    }
    else{
        layer.alert("密码不一致！");
    }
}
function add_user(){
    var username=document.getElementById("username").value;
    var password=document.getElementById("password").value;
    var password2=document.getElementById("password2").value;
    var newuser_qxbox=document.getElementsByClassName("new_qx_checkbox");
    var users=document.getElementsByClassName("user_id");
    var newuser_qx="";
    
    if( username=="" || password=="" || password2==""){
        layer.alert("不能留空！");
        return false;
    }
    for (let index = 0; index < users.length; index++) {
        if(users[index].innerHTML==username){
            layer.alert("该用户名已存在！");
            document.getElementById("username").value="";
            return false;
        }
    }
    //获取新用户权限
    for (let index = 0; index < newuser_qxbox.length; index++) {
        if(newuser_qxbox[index].checked){
            newuser_qx=newuser_qx +"," + newuser_qxbox[index].value;
        }
    }
    if(password==password2){
        var index1 = layer.load(3, {
            shade: [0.5,'#000'] //0.1透明度的白色背景
        });
        $.post(
            "controler.php?handle=add_user",
            {
                username:username,
                password:password,
                newuser_qx:newuser_qx
            },
            function (msg) {
                layer.close(index1);
                result(msg);
            }
        );
    }
    else{
        alert("密码不一致！");
    }
}
function dele(user_id){
    layer.confirm('确定要删除该管理员吗？', {icon: 3, title:'提示'}, function(index){
        layer.close(index);
        var index1 = layer.load(3, {
            shade: [0.5,'#000'] //0.1透明度的白色背景
        });
        $.post(
            "controler.php?handle=dele",
            {
                username:user_id
            },
            function (msg) {
                layer.close(index1);
                result(msg);
            }
        );
    });
}
function change_qx(user_id) {
    var newuser_qxbox=document.getElementsByClassName(user_id);
    //获取新用户权限
    var user_new_qx="";
    for (let index = 0; index < newuser_qxbox.length; index++) {
        if(newuser_qxbox[index].checked){
            user_new_qx=user_new_qx +"," + newuser_qxbox[index].value;
        }
    }
    var index1 = layer.load(3, {
        shade: [0.5,'#000'] //0.1透明度的白色背景
    });
    $.post(
        "controler.php?handle=change_qx",
        {
            username:user_id,
            user_new_qx:user_new_qx
        },
        function (msg) {
            layer.close(index1);
            result(msg);
        }
    );
}
function result(msg){
    var data=msg.split("||");
        if(data[0]=="1"){
            layer.alert(data[1],function(){
                location.reload();
            });
        }
        else{
            if(data[0]=="0"){
                layer.alert(data[1]);
            }
            else{
                layer.alert("请求出错，请稍后再试！");
            }
        }
}